package geektime.spring.data.mybatisdemo.service;

import geektime.spring.data.mybatisdemo.mapper.CoffeeMapper;
import geektime.spring.data.mybatisdemo.model.Coffee;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@CacheConfig(cacheNames = "coffee")
public class CoffeeService {
    @Autowired
    private CoffeeMapper coffeeMapper;

    @Transactional
    public int save(Coffee c) {
        return coffeeMapper.save(c);
    }

    @Transactional
    public int update(Coffee c) {
        return coffeeMapper.update(c);
    }

    @Transactional
    public int delete(Coffee c) {
        return coffeeMapper.delete(c);
    }
//    @Cacheable(cacheNames = "coffee",key = "#id")
    public List<Coffee> findByIdWithRowBounds(Long id, RowBounds rowBounds) {
        return  coffeeMapper.findByIdWithRowBounds(id,rowBounds);
    }
}
